{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from llama_index.llms.perplexity import Perplexity\n",
    "from dotenv import load_dotenv\n",
    "\n",
    "load_dotenv()\n",
    "\n",
    "pplx_api_key = os.getenv(\"PERPLEXITY_API_KEY\")\n",
    "\n",
    "llm = Perplexity(\n",
    "    api_key=pplx_api_key, model=\"mistral-7b-instruct\", temperature=0.5\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.55 s ± 192 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "from llama_index.core.llms import ChatMessage\n",
    "\n",
    "messages_dict = [\n",
    "    {\"role\": \"system\", \"content\": \"Be precise and concise.\"},\n",
    "    {\"role\": \"user\", \"content\": \"tell me about harry potter\"},\n",
    "]\n",
    "messages = [ChatMessage(**msg) for msg in messages_dict]\n",
    "\n",
    "external_response = llm.chat(messages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = Perplexity(\n",
    "    api_key=pplx_api_key, model=\"mixtral-8x7b-instruct\", temperature=0.5\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.36 s ± 132 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "from llama_index.core.llms import ChatMessage\n",
    "\n",
    "messages_dict = [\n",
    "    {\"role\": \"system\", \"content\": \"Be precise and concise.\"},\n",
    "    {\"role\": \"user\", \"content\": \"tell me about harry potter\"},\n",
    "]\n",
    "messages = [ChatMessage(**msg) for msg in messages_dict]\n",
    "\n",
    "external_response = llm.chat(messages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = Perplexity(\n",
    "    api_key=pplx_api_key, model=\"sonar-small-chat\", temperature=0.5\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.01 s ± 150 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "from llama_index.core.llms import ChatMessage\n",
    "\n",
    "messages_dict = [\n",
    "    {\"role\": \"system\", \"content\": \"Be precise and concise.\"},\n",
    "    {\"role\": \"user\", \"content\": \"tell me about harry potter\"},\n",
    "]\n",
    "messages = [ChatMessage(**msg) for msg in messages_dict]\n",
    "\n",
    "external_response = llm.chat(messages)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
